

<template>
  <div class="resume_header">
    <span>公司岗位审核</span>
  </div>
  <div class="resume_center">
    <el-table :data="filterTableData.slice((page - 1) * limit, page * limit)" style="width: 100%" height="400px"
      size="large">
      
      <el-table-column label="岗位名称" prop="jobName" width="190px" />
      <el-table-column label="所属公司" prop="businessName" width="190px" />
      <el-table-column label="提交人" prop="hrName" width="100px" />
      <el-table-column label="提交时间" prop="confirmTime" width="170px" />
      <el-table-column label="审核时间" prop="auditTime" width="170px" />
      <el-table-column label="审核状态" prop="auditState" width="88px" />
      <el-table-column label="操作类型" width="88px" >
        <template #default="scope">
        {{ scope.row.operationType=="add"?"添加岗位":"编辑岗位" }}
        </template>
      </el-table-column>
      <el-table-column align="right" min-width="280px">
        <template #header>
          <el-input v-model="search" size="default" placeholder="搜索" />
        </template>
        <template #default="scope">
          <el-button size="default" type="primary" @click="handleShowJObInfo(scope.$index, scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <PreAuditJobDialog v-if="preAuditJobInfoDialog" :closePreAuditJobInfoDialog="closePreAuditJobInfoDialog"
      :preAuditJobInfoDialog="preAuditJobInfoDialog" />

    <div class="pagination">
      <Pagination :page="page" :limit="limit" :handleSizeChange="handleSizeChange"
        :handleCurrentChange="handleCurrentChange" :filterTableData="filterTableData" :pagesizes="pagesizes" />
    </div>

  </div>

</template>
<script lang='ts' setup>

import {eGetAuditJobs,ePreAuditJobs} from "@/api/enterpriseApi"
import { computed, ref, onMounted, reactive, watch, onBeforeMount } from 'vue'
import { useStore } from "vuex"
import Pagination from "@/components/Pagination.vue"
import { data, elmessage, formatDate } from "@/hook/hook";
import { useRouter } from "vue-router"

import PreAuditJobDialog from "@/components/PreAuditJobDialog.vue"
const store = useStore()
const router = useRouter()


// 表格数据定义
interface Jobs {
  auditId: string
  jobId: string
  jobName: string
  hrId: string
  hrName: string
  confirmTime: string
  auditTime: string
  auditState: string
  isAudit: string
  operationType: string
  eId: string
  businessName: string
}
const tableData: Jobs[] = reactive([])

const search = ref('')
const filterTableData = computed(() =>

  tableData.filter(
    (data, index) =>
      !search.value ||
      // 通过岗位名称筛选
      data.jobName.toLowerCase().indexOf(search.value.toLowerCase()) !== -1
  )
)


// 分页器
const page = ref(1)
const pagesizes = ref([1, 2, 3, 4, 10, 20, 30, 40])
const limit = ref(10)

const handleSizeChange = (val: number) => {
  limit.value = val
  page.value = 1
}
const handleCurrentChange = (val: number) => {
  page.value = val
}

// 查看具体修改的内容
const preAuditJobInfoDialog = ref(false)

const job = store.state.adminState.auditjob
const getPreAuditJobInfo = (auditId: string) => {
  const newData = {
    ...data(),
    auditId: auditId
  }
  ePreAuditJobs(newData).then((res: any) => {
    if (res.data["code"] == "200") {
      job.auditId = res.data.datas[0].auditId
      job.jobId = res.data.datas[0].jobId
      job.jobName = res.data.datas[0].jobName
      job.jobAddress = res.data.datas[0].jobAddress
      job.jobEdu = res.data.datas[0].jobEdu
      job.jobAge = res.data.datas[0].jobAge
      job.jobEx = res.data.datas[0].jobEx
      job.jobSalary = res.data.datas[0].jobSalary
      job.jobIndustry = res.data.datas[0].jobIndustry
      job.jobDetail = res.data.datas[0].jobDetail


      job.hrId = res.data.datas[0].hrId
      job.hrName = res.data.datas[0].hrName
      job.hrEmail = res.data.datas[0].hrEmail
      job.hrPhone = res.data.datas[0].hrPhone

      job.isAudit = res.data.datas[0].isAudit
      job.auditTime = res.data.datas[0].auditTime
      job.confirmTime = res.data.datas[0].confirmTime
      job.auditState = res.data.datas[0].auditState
      job.operationType = res.data.datas[0].operationType
      job.auditResultContent = res.data.datas[0].auditResultContent

      job.eId = res.data.datas[0].eId
      job.businessName = res.data.datas[0].businessName

      preAuditJobInfoDialog.value = true
    } else if (res.data["code"] == "300") {
      elmessage(res.data["message"], res.data["type"])
      setTimeout(() => {
        router.replace("/login")
      }, 500);
      localStorage.clear()
    } else {
      console.log(res.data);

    }

  })
}
const handleShowJObInfo = (index: number, row: Jobs) => {
  getPreAuditJobInfo(row.auditId)
}

const closePreAuditJobInfoDialog = () => {
  preAuditJobInfoDialog.value = false
}


const init = () => {
  eGetAuditJobs(data()).then((res: any) => {
    if (res.data["code"] == "200") {
      res.data.datas.forEach((value: any, index: any, self: any) => {
        tableData.push({ ...value })
      })
    } else if (res.data["code"] == "300") {
      elmessage(res.data["message"], res.data["type"])
      setTimeout(() => {
        router.replace("/login")
      }, 500);
      localStorage.clear()
    } else {
      console.log(res.data);

    }
  })
}

onBeforeMount(() => {
  init()
})


</script>
<style scoped>
.pagination {
  float: right;
  margin-right: 50px;
  /* right: 150px; */
}

.resume_center {
  font-family: '微软雅黑';
  height: 800px;
  background-color: #FFF;
}

.resume_header {
  background-color: rgb(215, 215, 215);
  height: 50px;
  display: flex;
  align-items: center;
  padding-left: 20px;
  justify-content: space-between;
}

a {
  text-decoration: none;
  color: #000;
}
</style>